package br.usp.ime.origami.view;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

import javax.swing.JFrame;

import br.usp.ime.origami.model.MovingPoint;
import br.usp.ime.origami.model.MovingTriangle;
import br.usp.ime.origami.model.MovingTriangulation;
import br.usp.ime.origami.model.Polygonable;
import br.usp.ime.origami.model.SimplePoint;

public class Drawer extends Canvas {

    private Map<Polygonable, Color> figures = new LinkedHashMap<Polygonable, Color>();

    private Map<Polygonable, Color> filledFigures = new LinkedHashMap<Polygonable, Color>();

    public void addTriangle(Polygonable f, Color c) {
        this.figures.put(f, c);
    }

    public void addFilledTriangle(Polygonable f, Color c) {
        this.filledFigures.put(f, c);
    }

    public void clear() {
        figures = new LinkedHashMap<Polygonable, Color>();
        filledFigures = new LinkedHashMap<Polygonable, Color>();
    }

    @Override
    public void paint(Graphics g) {
        this.setVisible(true);

        g.setColor(Color.WHITE);
        g.clearRect(0, 0, 800, 600);
        for (Polygonable f : figures.keySet()) {
            g.setColor(figures.get(f));
            Polygon p = fitOnScreen(f.toPolygon());
            g.drawPolygon(p);
        }
        for (Polygonable f : filledFigures.keySet()) {
            g.setColor(filledFigures.get(f));
            Polygon p = fitOnScreen(f.toPolygon());
            g.fillPolygon(p);
        }
    }

    private Polygon fitOnScreen(Polygon p) {
        
        // TODO
        return p;
    }

}
